package com.umeng.soexample.mvp.persenter;

import com.umeng.lib_core.mvp.presenter.BasePresenter;
import com.umeng.soexample.bean.HomeMenuEntity;
import com.umeng.soexample.mvp.contract.MainContract;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class MainPresenter extends BasePresenter<MainContract.IMaianView, MainContract.IMainModel> {
    @Inject
    public MainPresenter(MainContract.IMaianView iMaianView, MainContract.IMainModel iMainModel) {
        super(iMaianView, iMainModel);
    }

    //发起获取菜单列表网络请求
    public void requestMenu(){
        m.homemenu().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeMenuEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(HomeMenuEntity homeMenuEntity) {
                        v.success(homeMenuEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        v.hideDialog();
                        v.showMessage("" + e);
                    }

                    @Override
                    public void onComplete() {
                        v.hideDialog();
                    }
                });
    }
}
